﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.CodeAnalysis;

namespace SDF.Primitives
{
    /// <summary>
    /// Notifies clients that data within an object has changed.
    /// </summary>
    public interface INotifyDataChanged
    {
        /// <summary>
        /// Fired when the data inside an object has changed.
        /// </summary>
        event EventHandler<DataChangedEventArgs> DataChanged;
    }

    #region DataChangedEventArgs class

    /// <summary>
    /// Defines the arguments of a DataChanged event.
    /// </summary>
    public class DataChangedEventArgs : EventArgs
    {
        #region Constructor

        /// <summary>
        /// Creates a new instance of DataChangedEventArgs.
        /// </summary>
        /// <param name="source">The object where the data changed.</param>
        /// <param name="eventArguments">The original event argument that contains information about the changes.</param>
        [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers",
           Justification = "This is not an event handler, even tough it has the same signature.")]
        public DataChangedEventArgs(object source, EventArgs eventArguments):
            this(source, eventArguments, false)
        {
        }

        /// <summary>
        /// Creates a new instance of DataChangedEventArgs.
        /// </summary>
        /// <param name="source">The object where the data changed.</param>
        /// <param name="eventArguments">The original event argument that contains information about the changes.</param>
        /// <param name="affectsRendering">Indicates if this change should affect the rendering of the object.</param>
        public DataChangedEventArgs(object source, EventArgs eventArguments, bool affectsRendering)
        {
            if (source == null)
                throw new ArgumentNullException("source");
            if (eventArguments == null)
                throw new ArgumentNullException("eventArguments");
            Source = source;
            EventArguments = eventArguments;
            AffectsRendering = affectsRendering;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The object where the data changed.
        /// </summary>
        public object Source { get; private set; }

        /// <summary>
        /// The original event argument that contains information about the changes.
        /// </summary>
        public EventArgs EventArguments { get; private set; }

        public bool AffectsRendering { get; set; }

        #endregion
    }

    #endregion
}
